home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_7 / traprl.m < prev   
Encoding:
Text File  |  1994-06-05  |  401 b   |  16 lines  |  [MATF/MATL]

  1. function s = traprl(f,a,b,m)
  2. % s = traprl(f,a,b,m)
  3. % Quadrature using the trapezoidal rule.
  4. % f is the name of the function, input.
  5. % a is the left  endpoint, input.
  6. % b is the right endpoint, input.
  7. % m is the number of subintervals, input.
  8. % s is the trapezoidal rule sum, output.
  9. h  = (b - a)/m;
  10. s = 0;
  11. for k=1:(m-1),
  12.   x = a + h*k;
  13.   s = s + feval(f,x);
  14. end
  15. s = h*(feval(f,a)+feval(f,b))/2 + h*s;
  16.